/*****************************************************************************
*    Copyright (C) 2009 ALi Corp. All Rights Reserved.
*    
*    Company confidential and Properietary information.       
*    This information may not be disclosed to unauthorized  
*    individual.    
*    File: lib_pvr3.h
*   
*    Description: 
*    
*    History: 
*    Date           Athor        Version        Reason
*    ========       ========     ========       ========
*    2009/3/4       Roman		3.0.0			Create         
*    2010/6/7       Jason		3.0.1			Add 2 APIs
*        
*****************************************************************************/
#ifndef	__LIB_PVR3_H__
#define	__LIB_PVR3_H__

#include <types.h>
#include <sys_config.h>
#include <basic_types.h>
#include <api/libci/ci_plus.h>

#include "lib_pvr_eng.h"
#include "lib_pvr_mgr.h"

//##: DVR module initial and cleanup functions
RET_CODE  	pvr_attach(PPVR_MGR_CFG cfg, PPVR_CFG ini_param);
INT32 		pvr_register(UINT32 param1,UINT32 param2);
INT32 		pvr_cleanup(void);
INT32 		pvr_cleanup_disk(UINT32 param);
RET_CODE 	pvr_set_disk_use(UINT8 use, const char *mount_name);
enum PVR_DISKMODE	pvr_get_cur_mode(char *rec_disk, char *tms_disk);

//##: DVR recording API
PVR_HANDLE	pvr_r_open(struct record_prog_param *param);
UINT32		pvr_r_trans(PVR_HANDLE handle);
BOOL		pvr_r_close(PVR_HANDLE *handle, BOOL sync);
RET_CODE	pvr_r_changemode(PVR_HANDLE handle);
void		pvr_r_set_scramble(void);
void        pvr_r_set_scramble_ext(BOOL scramble);
UINT32		pvr_r_get_time(PVR_HANDLE handle);
void 		pvr_r_set_ts_file_size(UINT8 G_num);
UINT32 		pvr_r_get_bitrate(UINT8 dmx_id, UINT16 v_pid, UINT16 a_pid);
UINT8 		pvr_r_get_nim_id(PVR_HANDLE handle);
UINT8 		pvr_r_get_dmx_id(PVR_HANDLE handle);
UINT32 		pvr_r_get_channel_id(PVR_HANDLE handle);
RET_CODE	pvr_r_pause(PVR_HANDLE handle);
RET_CODE	pvr_r_resume(PVR_HANDLE handle);
PVR_STATE 	pvr_r_get_state(PVR_HANDLE handle);

//##: DVR playback API
PVR_HANDLE 	pvr_p_open(UINT16 index, PVR_STATE state, UINT8 speed, UINT32 start_time, UINT8 config);
PVR_HANDLE 	pvr_p_open_ext(struct playback_param *param);
BOOL		pvr_p_close(PVR_HANDLE *handle, UINT8 stop_mode, UINT8 vpo_mode, BOOL sync);
#ifdef _INVW_JUICE   
BOOL		pvr_p_close_ext(PVR_HANDLE *handle, struct playback_stop_param *stop_param);
#endif
//##: DVR playback state speed!
BOOL	pvr_p_play(PVR_HANDLE handle);
BOOL	pvr_p_pause(PVR_HANDLE handle);
BOOL	pvr_p_revslow(PVR_HANDLE handle, UINT8 speed);
BOOL	pvr_p_slow(PVR_HANDLE handle, UINT8 speed);
BOOL	pvr_p_step(PVR_HANDLE handle);
BOOL	pvr_p_fast_backward(PVR_HANDLE handle, UINT8 speed);
BOOL	pvr_p_fast_forward(PVR_HANDLE handle, UINT8 speed);
BOOL	pvr_p_timesearch(PVR_HANDLE handle, UINT32 ptm);
BOOL	pvr_p_jump(PVR_HANDLE handle, INT32 ptm);
BOOL 	pvr_p_seek(PVR_HANDLE handle, UINT32 pos);
BOOL	pvr_p_stop(PVR_HANDLE handle);
BOOL 	pvr_p_lock_switch(PVR_HANDLE handle, UINT32 lock_en);

//##: DVR playback information functions
UINT32 		pvr_p_get_pos(PVR_HANDLE handle);
UINT32		pvr_p_get_pos_time(PVR_HANDLE handle);
UINT32 		pvr_p_save_cur_pos(PVR_HANDLE handle); //for last play
UINT32		pvr_p_get_lastplay_pos(UINT16 index);
INT8 		pvr_p_get_direct(PVR_HANDLE handle);
UINT8		pvr_p_get_speed(PVR_HANDLE handle);
PVR_STATE	pvr_p_get_state(PVR_HANDLE handle);
UINT32		pvr_p_get_time(PVR_HANDLE handle);
UINT8 		pvr_p_get_dmx_id(PVR_HANDLE handle);

void 		pvr_resume_play_channel(void);
void 		pvr_p_set_ttx_lang(PVR_HANDLE handle);
void 		pvr_p_set_subt_lang(PVR_HANDLE handle);
void 		pvr_set_logo_id(UINT32 logo_id);
void 		pvr_p_switch_audio_pid(PVR_HANDLE handle, UINT16 pid);
void        pvr_p_switch_audio_pid_list(PVR_HANDLE handle, UINT16 *pid_list);
void		pvr_p_switch_audio_channel(PVR_HANDLE handle, UINT8 a_ch);

UINT8 		pvr_p_get_dmx_id(PVR_HANDLE handle);

UINT8 		pvr_get_HDD_info(struct dvr_HDD_info *partition_info);

UINT32		pvr_get_tms_capability(void);//the return value is in secounds!
UINT32 		pvr_p_save_cur_pos(PVR_HANDLE handle); //for last play
UINT32		pvr_p_get_lastplay_pos(UINT16 index);
RET_CODE 	pvr_set_bookmark(UINT16 record_idx, UINT32 mark_time);
UINT8 		pvr_get_bookmark(UINT16 record_idx, UINT32 *mark_ptm_array);
RET_CODE	pvr_set_agelimit(UINT16 record_idx, UINT32 ptm, UINT32 age);
UINT8		pvr_get_agelimit(UINT16 record_idx, UINT32 ptm);
RET_CODE	pvr_set_ratingctl(UINT16 record_idx, UINT32 ptm, UINT32 ratingctl);
UINT32		pvr_get_ratingctl(UINT16 record_idx, UINT32 ptm);
// DTG_PVR : event name and detail 
RET_CODE pvr_set_event_detail(UINT16 record_idx, UINT8 *pDetail, UINT32 len, UINT8 type);
UINT8* pvr_get_event_detail(UINT16 record_idx, UINT8 type);
RET_CODE pvr_set_event_name(UINT16 record_idx, UINT8* event_name);
UINT8* pvr_get_event_name(UINT16 record_idx);

//##: Recording list management API
#ifdef _INVW_JUICE   
void pvr_get_path( UINT16 record_idx, char *path);
#endif
UINT16	pvr_get_rl_count(void);
void		pvr_get_rl_info(UINT16 rl_id, struct ListInfo *info);
UINT16	pvr_get_rl_info_by_pos(UINT16 pos, struct ListInfo *info);
UINT16 	pvr_get_index(PVR_HANDLE handle);
void		pvr_set_rl_info(UINT16 rl_id, struct ListInfo info);
BOOL 	pvr_set_tms_size(UINT32 tms_size);//unit is K bytes
void    pvr_set_tms_level(UINT8 percent);
BOOL 	pvr_check_rl_del(void);
void 	pvr_clear_rl_del(void);
void 	pvr_save_rl(UINT16 index);
void		pvr_update_rl(void);
BOOL 	pvr_check_tms2rec(void);

RET_CODE	pvr_list_sort(enum sort_type mode, UINT8 order);

//##: HDD information
BOOL 	pvr_format_HDD(UINT8 mode);
UINT8	pvr_get_HDD_info(struct dvr_HDD_info *hdd_info);
void		pvr_check_disk(void);
BOOL 	pvr_p_use_tsgen(void);

//##: the following function is for the DMX and the VOB cache
INT32		pvr_p_request(PVR_HANDLE handle, UINT8 **addr, INT32 length, INT32 *indicator);
BOOL		pvr_r_update(PVR_HANDLE handle, UINT32 size, UINT16 offset);
INT32		pvr_r_request(PVR_HANDLE handle, UINT8 **addr, INT32 length);
PVR_HANDLE	pvr_get_handle_to_dmx(UINT32 dmx_id);

void pvr_r_set_record_all(BOOL bRecordAll);
BOOL pvr_r_get_record_all(void);

//char *pvr_get_root_dir_name(void);       // return "ALiDvr"

// interfaces for CC TSG task
void cc_tsg_task_init(void);
RET_CODE cc_tsg_task_start(UINT32 prog_id);
RET_CODE cc_tsg_task_stop(void);

BOOL cc_tsg_task_is_running(void);

int pvr_tms_vol_cleanup(void);
int pvr_tms_vol_init(void);

UINT8 pvr_check_record_active(void);
RET_CODE pvr_p_set_preview_mode(PVR_HANDLE handle, BOOL mode);
UINT32 pvr_set_write_read_cache_ratio(UINT32 ratio);
UINT32 pvr_get_write_read_cache_ratio();
#endif //__LIB_PVR3_H__
